use crate::uart::uart_send_string;
use core::fmt::{Arguments, Write};
use lock::Mutex;

struct SerialWriter;

static SERIAL_WRITER: Mutex<SerialWriter> = Mutex::new(SerialWriter);

impl Write for SerialWriter {
    fn write_str(&mut self, s: &str) -> core::fmt::Result {
        uart_send_string(s);
        Ok(())
    }
}

#[allow(dead_code)]
pub fn serial_write_str(s: &str) {
    SERIAL_WRITER.lock().write_str(s).unwrap();
}

pub fn serial_write_fmt(fmt: Arguments) {
    SERIAL_WRITER.lock().write_fmt(fmt).unwrap();
}
